#!/usr/local/bin/python
# -*- coding:utf-8 -*-
from tutorial.mysqlmoudel.myusesql.spidersql import SpiderSql
from tutorial.mysqlmoudel.sqlbuilder import MysqlBuilder
from tutorial.mysqlmoudel.sqlfactory import Abssql

mysql = Abssql.getsqlfractry().mysqlFractry("mysql")
builder = MysqlBuilder('../config/mysql.ini', 'mysqllocalhost')
moudle = builder.build_all().get_moudle().todict()
print(moudle)
mysql.link(moudle)
spidersql = SpiderSql()
cursor = mysql.cursor



with open("C:\\Users\\XD\\Desktop\\proxyIP.txt", 'r+') as f:
    ip = 1
    sql = spidersql.deletemyip()  # 保存到数据库
    print sql
    cursor.execute(sql)
    mysql.db.commit()
    while ip:
        ip = f.readline()
        print ip
        if ip:
            try:
                sql = spidersql.joinproxyip(ip)  # 保存到数据库
                print sql
                cursor.execute(sql)
                mysql.db.commit()
            except:
                print ("sql execute err,please check")
                mysql.db.rollback()
    f.close()

cursor.close()
mysql.db.commit()
mysql.close()